import {reqBannerList, reqCategoryList, reqFloorList} from '@/api';
const state = {
    categoryList:[],
    bannerList: [], // 首页轮播数据
    floorList: [], // 首页楼层数据
}
const mutations = {
    RECEIVE_CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList;
    },
    RECEIVE_BANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    RECEIVE_FLOORLIST(state,floorList){
        state.floorList = floorList
    }
}

const actions = {
    async getCategoryList({commit}){
        try {
            const res = await reqCategoryList();
            commit('RECEIVE_CATEGORYLIST',res.data);
        } catch (error){
            alert('获取三级分类数据失败');
        }
    },
    async getBannerList({commit}){
        try {
            const res = await reqBannerList();
            if (res && res.code === 200){
                commit('RECEIVE_BANNERLIST',res.data);
                
            }
        }catch (error){
            console.log('获取轮播数据失败');
        }
    },
    async getFloorList({ commit }) {
        try {
            const result = await reqFloorList();
            if (result && result.code === 200) {
                commit('RECEIVE_FLOORLIST', result.data)
            }
        } catch (error) {
            console.error('获取楼层数据失败')
        }
    }
}
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters
}